﻿using System;
using System.Drawing;
using DllExport;
namespace CPP2CShape
{
    class Program
    {
        public static long CurrentTimeStamp(bool isMinseconds = false)
        {
            var ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            long times = Convert.ToInt64(isMinseconds ? ts.TotalMilliseconds : ts.TotalSeconds);
            return times;
        }
        static void Main(string[] args)
        {
            Console.WriteLine("开始");

            //Yolo5-Onnx目标检测测试
            const float confThreshold = 0.3f;
            const float iouThreshold = 0.4f;
            TestPersonRef ntestPer = new TestPersonRef();
            Yolo5Detetor my5Det = new Yolo5Detetor("W:/Gitee/NewWork/Detector/bin/Debug/model/yolov5x_offi.onnx", true, 640, 640);
            String[] calsses = { "person","bicycle","car","motorbike","aeroplane","bus","train","truck",
            "boat","traffic light","fire hydrant","stop sign","parking meter","bench","bird","cat","dog","horse","sheep",
            "cow","elephant","bear","zebra","giraffe","backpack","umbrella","handbag","tie","suitcase","frisbee","skis",
            "snowboard","sports ball","kite","baseball bat","baseball glove","skateboard","surfboard","tennis racket",
            "bottle","wine glass","cup","fork","knife","spoon","bowl","banana","apple","sandwich","orange","broccoli",
            "carrot","hot dog","pizza","donut","cake","chair","sofa","pottedplant","bed","diningtable","toilet","tvmonitor",
            "laptop","mouse","remote","keyboard","cell phone","microwave","oven","toaster","sink","refrigerator","book","clock",
            "vase","scissors","teddy bear","hair drier","toothbrush"};
            my5Det.setClassNames(calsses);

            DOutput[] resOuts;
            //resOuts = my5Det.detects("W:/Gitee/NewWork/Detector/bin/Debug/images/111.jpeg", confThreshold, iouThreshold);
            Bitmap img = new Bitmap(@"W:/Gitee/NewWork/Detector/bin/Debug/images/1021bubble.bmp");
            resOuts = my5Det.detectb(img, confThreshold, iouThreshold);
            Console.WriteLine("结果数量{0}", resOuts.Length);
            if (resOuts.Length > 0)
            {
                for (int i = 0; i < resOuts.Length; i++)
                {
                    Console.WriteLine("类型:{0},置信度:{1}，x:{2},y:{3},w:{4},h:{5}",
                        resOuts[i].className, resOuts[i].confidence,
                        resOuts[i].x, resOuts[i].y, resOuts[i].width, resOuts[i].height);
                }
            }
            int times = 400;
            long sta = CurrentTimeStamp(true);
            for (int i = 0; i < times; i++)
            {
                //my5Det.detects("W:/Gitee/NewWork/Detector/bin/Debug/images/111.jpeg", confThreshold, iouThreshold);
                my5Det.detectb(img, confThreshold, iouThreshold);
            }
            long sto = CurrentTimeStamp(true);
            Console.WriteLine("开始时间{0},结束时间{1}，平均每张时间{2}", sta, sto,((sto-sta)/times));



            while (true);
        }
    }
}
